<%--
 *  File:    DataCleanPeriodSummary.jsp
 *  @Author: Jamesli
 *  Date:    2010/06/21
 *
 *  Copyright (C) 2000 - 2010 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.DataCleanPeriodSummary"); 

  //init param
  String strModuleName = "CM";
  String privilegeCode = "E0131";
  String contextPath = request.getContextPath();
  String strTableName = "v_datacleanperiodsummary";
%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title>DataCleanPeriodSummary</title>
<PageFlow:CheckPageFlow pageName="p_datacleanperiodsummary"/>
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<script>
<%if((Integer)pageContext.getAttribute("dcperiodid") == null){
	%>
	parent.down.location.href = "<%=contextPath %>/Blank.jsp?<%= OvalTools.randomURL() %>";
	<%
	}
%>
function clickRow(id, rownum)
{
  document.cform.periodid.value = id;
  document.cform.rownum.value = rownum;
}

function page_delete()
{
  var id = document.cform.periodid.value;

  if(id == null || id.length == 0 || id == "" || id == "-1")
    return;
  
  var rownum = cform.rownum.value;
  if(eval('cform.fakestatus' + rownum + '.value') != 0){
	  alert("<%= message.getMessageDesc("CANNOT_DELETE_PERIOD_IN_USE")%>");
	  return;
  }

  if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL")%>")) return;
  
  document.cform.actionname.value = "delete";
  isRunning = true;
  document.cform.submit();
  
}
function page_edit()
{
  var rownum = cform.rownum.value;
  if(eval('cform.fakestatus' + rownum + '.value') == 1){
	  alert("<%= message.getMessageDesc("STARTEDUP_PERIOD_CANT_MODIFIED")%>");
	  return;
  }
	
  var periodid = document.cform.periodid.value;
  if(periodid == null || periodid.length == 0 || periodid == "" || periodid == "-1")
    return;
  parent.down.location.href = "DataCleanPeriodEdit.jsp?<%= OvalTools.randomURL() %>&periodid=" + periodid;
}

function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  editform.action = "DataCleanPeriodSummary.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}

function page_detail(id,rownum){
	if(eval('cform.fakestatus' + rownum + '.value') == 1){
		parent.down.location.href = "DataCleanPeriodDetailInfo.jsp?<%= OvalTools.randomURL() %>&periodid=" + id;
	}else{
		parent.down.location.href = "DataCleanPeriodDetail.jsp?<%= OvalTools.randomURL() %>&periodid=" + id;
	}
}
</script>
</head>
<body>
<% //--------------------------------------  page location --%>
	<%@ include file="/inc/PageLocation.inc" %>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
<form name="cform" method="post" action="<%=contextPath %>/Dispatcher"  target="_parent">
	<input type="hidden" name="pagename" value="p_datacleanperiodsummary">
	<input type="hidden" name="actionname">
	<input type="hidden" name="dcperiodid">
   <tr>
    <td> 
      <table width="100%" border="0" cellspacing="0">  
         <%@ include file="/inc/SummarySearch.inc" %>
       </table>
    </td>
  </tr>
  <tr> 
    <td> 
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
         <tr  class="deepblue-left"> 
            <td width="4%" class="title_center">&nbsp;</td>
            <td class="title_center"><a href="javascript:page_summary('orderby','periodname')"><%= label.getLabelName("L_PeriodName") %></a></td>
            <td width="18%" class="title_center"><a href="javascript:page_summary('orderby','iscontinuum')"><%= label.getLabelName("L_IsPeriodConsecutive") %></a></td>
            <td width="18%" class="title_center"><a href="javascript:page_summary('orderby','startdate')"><%= label.getLabelName("L_PeriodStartDate") %></a></td>
            <td width="18%" class="title_center"><a href="javascript:page_summary('orderby','enddate')"><%= label.getLabelName("L_PeriodEndDate") %></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','status')"><%= label.getLabelName("L_Status") %></a></td>
         </tr>
         <%
             int j = 0;
             String strClassType = new String(); 
             Integer nDefaultPeriodId = new Integer(-1);  
             boolean bHasChecked = false;
             Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
             if(totalsummary == null) totalsummary = new Vector();
             
             //4reload the checked period
             Integer periodid = (Integer)pageContext.getAttribute("dcperiodid");
          %>
          <logic:iterate id="summary" collection="<%= totalsummary %>">                      
         <%
            HashMap summaryMap = (HashMap)pageContext.getAttribute("summary");
            if(summaryMap == null) summaryMap = new HashMap();
            String strIsChecked = new String("");
            
            //redefine status
            String fakestatus = "";
            Integer status = (Integer)summaryMap.get("status");
            if(status != null){
            	if(status.intValue() == 10){
            		fakestatus = "0";
            	}else if(status.intValue() == 43){
            		fakestatus = "1";
            	}
            }
            
            if(j%2 == 1){
              strClassType = "td-listrom";             
            }else{                    
              strClassType = "";
            }
            
            Integer currentperiodid = (Integer)summaryMap.get("datacleanperiodid");
            if(currentperiodid == null) currentperiodid = new Integer("-1"); 
            
            if((periodid == null && !bHasChecked) || (periodid != null && periodid.intValue() == currentperiodid.intValue())){
	              strIsChecked = "Checked";                       
	              bHasChecked = true;
	              nDefaultPeriodId = currentperiodid;
	        }
            String disabled = "";
            Integer periodidspecial = (Integer)summaryMap.get("datacleanperiodid");
            if(periodidspecial != null && periodidspecial.intValue() < 100000000){ disabled = "disabled='disabled'";}
            j++;     
          %>
           <tr onmouseover="this.className='tr-over'" onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'"  onClick="javascript:radiotrue('radio<%=JspHelper.filterNull(j)%>');clickRow('<custom:write property="datacleanperiodid" name="summary"/>','<%=j + "" %>')" class="<%=JspHelper.filterNull(strClassType)%>">
            <td>
              <input class="normalradio" id="radio<%=JspHelper.filterNull(j )%>" type="radio" name="checkdept" value="" <%=JspHelper.filterNull( strIsChecked)%> <%=disabled %>>
            </td>
            <td>&nbsp;<A onclick="page_detail('<custom:write property="datacleanperiodid" name="summary"/>','<%=j %>')"><custom:write property="periodname" name="summary"/></A></td>
            <td>&nbsp;<custom:write property="iscontinuum" name="summary"/></td>
            <td>&nbsp;<custom:write property="startdate" name="summary"/></td>
            <td>&nbsp;<custom:write property="enddate" name="summary"/></td>
            <td class="td_center"><custom:write dictType="Status" property="status" name="summary"/></td>
            <custom:hidden property="fakestatus" value="<%=fakestatus %>" colIndex="<%=new Integer(j) %>"/>
          </tr>
          </logic:iterate>
          <%//---------------set default value-------------------- %>
          <input type="hidden" name="periodid" value="<%=JspHelper.filterNull( nDefaultPeriodId )%>">
          <input type="hidden" name="rownum" value="1">
      <% //--------------------------------------  flipping page --%>
      <%@ include file="/inc/SummaryAction.inc" %>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr> 
          <td class="summary_top"></td>
        </tr>
        <tr> 
          <td class="td_center">
            <a onclick="parent.down.location.href='DataCleanPeriodEdit.jsp?<%= OvalTools.randomURL() %>';"><custom:button type="1" label="L_New" imgsrc="new.gif" border="0" style="width:60" privilegeCode="MB-QJ01"/></a>
            <a onclick="page_edit()"><custom:button type="1" label="L_Edit" imgsrc="edit.gif" border="0" style="width:60" privilegeCode="MB-QJ02"/></a>
			<%if(privilegeSet != null && privilegeSet.contains("B6080")){%> 
            <a onclick="page_delete()"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60" privilegeCode="MB-QJ03"/></a>
            <%}%>
		  </td>
        </tr>
      </table>
    </td>
  </tr>
  </form>
</table>
</body>
</html>